/** @file         board.c
 *  @brief        简要说明
 *  @details      详细说明
 *  @author       lzm
 *  @date         2023-04-20 16:26:39
 *  @version      v1.0
 *  @copyright    Copyright By lizhuming, All Rights Reserved
 *
 **********************************************************
 *  @LOG 修改日志:
 **********************************************************
*/

#include <stdio.h>

#include <rthw.h>
#include <rtthread.h>

#include <stdlib.h>
#include <unistd.h>

#include "board.h"
#include "uart_console.h"

/**
 * This function is used to display a string on console, normally, it's invoked by rt_kprintf
 *
 * @param str the displayed string
 */
void rt_hw_console_output(const char* str)
{
    printf("%s", str);
}

/**
 * @addtogroup simulator on win32
 */
rt_uint8_t *rt_hw_sram_init(void)
{
    rt_uint8_t *heap;
    heap = malloc(RT_HEAP_SIZE);
    if (heap == RT_NULL)
    {
        rt_kprintf("there is no memory in pc.");
        exit(1);
    }
#ifdef RT_USING_HEAP
    /* init memory system */
    rt_system_heap_init((void*)heap, (void*)&heap[RT_HEAP_SIZE - 1]);
#endif
    return heap;
}

void rt_hw_win32_low_cpu(void)
{
    /* in linux */
    sleep(1);
}

void rt_hw_exit(void)
{
    rt_kprintf("RT-Thread, bye\n");

    exit(0);
}

#if defined(RT_USING_FINSH)
#include <finsh.h>
FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_exit, exit, exit rt - thread);
MSH_CMD_EXPORT_ALIAS(rt_hw_exit, quit, exit rt-thread);
#endif /* RT_USING_FINSH */

/**
 * This function will initial win32
 */
int rt_hw_board_init(void)
{
    /* init system memory */
    rt_hw_sram_init();


#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif

    return 0;
}
